package jsyf.oa.web.wreport;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.FastJsonConvert;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wreport.WReportExpensesFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2018/3/22.
 */
@Api(value = "临时费用手机上显示接口", description = "临时费用手机上显示接口")
@Controller
@RequestMapping("/wReportExpenses")
public class WReportExpensesController {

    @Autowired
    private WReportExpensesFacade wReportExpensesFacade;

    @ResponseBody
    @RequestMapping(value = "/getPhoneFees.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "临时费用在手机上显示",
            notes = "临时费用在手机上显示",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'userId':''}", dataType = "String", paramType = "body")
    public void getPhoneFees( HttpServletResponse response, @RequestBody String jsonData){
        JSONObject jsonObject = FastJsonConvert.convertJSONToObject(jsonData, JSONObject.class);

        List<JSONObject> result = this.wReportExpensesFacade.getPhoneFees(jsonObject);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }


    @ResponseBody
    @RequestMapping(value = "/addPhoneFees.json", method = RequestMethod.POST)
    public void addPhoneFees(HttpServletResponse response, @RequestBody String jsonData){
        String result = this.wReportExpensesFacade.addPhoneFees(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }

    @ResponseBody
    @RequestMapping(value = "/remove.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "删除手机显示",
            notes = "删除手机显示",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'temporaryCost':''}", dataType = "String", paramType = "body")
    public void remove(HttpServletResponse response, @RequestBody String jsonData){
        Boolean result = this.wReportExpensesFacade.remove(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result.toString()));
    }

    @ResponseBody
    @RequestMapping(value = "/updatePhoneFees.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改手机显示",
            notes = "修改手机显示",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "[{id:''},{id:''}]", dataType = "String", paramType = "body")
    public void updatePhoneFees(HttpServletResponse response, @RequestBody String jsonData){
        JSONObject result = this.wReportExpensesFacade.updatePhoneFees(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(result));
    }


}